/*****************************************************************
**                                                             	**
**  Copyright (C) 2004 Amlogic,Inc.                            	**
**  All rights reserved                                        	**
**        Filename : Win15Pic.c /Project:AVOS		       **
**        Revision : 1.0                                       	**
**                                                             	**
*****************************************************************/
#include "../menu.h"
#include "Win15PicEvent.h"
#include "./win/NetmenuSetupEvent.h"
int TOP;
INT32S Win15PicMsgProc(PHWND hwnd, INT32U msg_type, INT32S lpParam)
{
    switch( msg_type)
    {
        case WM_SHOWWINDOW:
        return Win15PicOnShow(hwnd, lpParam) ;
    }
    return 0 ;
}
INT32S Win15PicBarMsgProc(PHWND hwnd, INT32U msg_type, INT32S lpParam)
{
    switch( msg_type){
        case WM_SHOWWINDOW:
            return Win15PicBarOnShow(hwnd, lpParam) ;
        case WM_KEYDOWN:
            return Win15PicBarOnKeyPress(hwnd, lpParam) ;
    }
    return 0 ;
}

void SetWin15PicPalette(void)
{
    YUVENTRY mask_para[4] = {0,4095,4095,4095};
    AWSetAlphaMask(0,4, mask_para);
    YUVENTRY palette_para[16] = {0x8000 | 16392,0x8000 | 16216,0x8000 | 17880,0x8000 | 16392,16280,16184,16088,16040,16024,15880,15208,15720,15016,15064,15304,15144};
    AWSetPalette(0,16, palette_para);
    return ;
}

void SetWin15PicPos(HWND* pControl, INT8U CurOsdSize)
{
    switch(CurOsdSize)
      {
        default:
            RECT NormalWindowRect = {0,0,720,576};
            pControl->winrect = NormalWindowRect;
            CREATEWINDOWPARAM NormalWindowPara = {1,{{0,0,720,576},{0,0,0,0},{0,0,0,0},{0,0,0,0}},{0,0,0,0},SetWin15PicPalette};
            AWSendMessage(pControl, WM_WINDOW_RESET_DRAW_AREA, (INT32S)&NormalWindowPara);
            break ;
      }
       
    //end of switch
    return;
}

HWND *CreateControlWin15Pic(HWND* pParent)
{
    HWND* pNewControl;
    CREATEWINDOWPARAM window_para = {1,{{0,0,720,576},{0,0,0,0},{0,0,0,0},{0,0,0,0}},{PF_PALETTE_256,0,0,0},SetWin15PicPalette};
    //Create Menu Window -- 1
    pNewControl = AWCreateWinControl("TWindow","Win15Pic",WS_OVERLAPPEDWINDOW,
		         0,0,720,576,NULL, (INT32S)&window_para,Win15PicMsgProc) ;
    pNewControl->win_id = 0 ;
    return pNewControl;
}


void Set15PicBarPos(HWND* pControl, INT8U CurOsdSize)
{
    int iLoop;
    
    switch(CurOsdSize){
	case OsdSize576iCVBS:
	case OsdSize576i:
	case OsdSize576p:
            pControl->winrect.top = pControl->parent->winrect.top + 0;
            pControl->winrect.left = pControl->parent->winrect.left + 0;
            pControl->winrect.width = 720;
            pControl->winrect.height = 576;
            pControl->draw_info_num = 26;
            RECT StandardDrawRect[26] = {
            {pControl->winrect.left + 0,pControl->winrect.top + 48,720,480},
            {pControl->winrect.left + 30,pControl->winrect.top + 58,120,78},
            {pControl->winrect.left + 72,pControl->winrect.top + 158,114,98},
            {pControl->winrect.left + 188,pControl->winrect.top + 158,114,98},
            {pControl->winrect.left + 304,pControl->winrect.top + 158,114,98},
            {pControl->winrect.left + 420,pControl->winrect.top + 158,114,98},
            {pControl->winrect.left + 536,pControl->winrect.top + 158,114,98},
            {pControl->winrect.left + 72,pControl->winrect.top + 258,114,98},
            {pControl->winrect.left + 188,pControl->winrect.top + 258,114,98},
            {pControl->winrect.left + 304,pControl->winrect.top + 258,114,98},
            {pControl->winrect.left + 420,pControl->winrect.top + 258,114,98},
            {pControl->winrect.left + 536,pControl->winrect.top + 258,114,98},
            {pControl->winrect.left + 72,pControl->winrect.top + 358,114,98},
            {pControl->winrect.left + 188,pControl->winrect.top + 358,114,98},
            {pControl->winrect.left + 304,pControl->winrect.top + 358,114,98},                              
            {pControl->winrect.left + 420,pControl->winrect.top + 358,114,98},
            {pControl->winrect.left + 536,pControl->winrect.top + 358,114,98},            
            {pControl->winrect.left + 558,pControl->winrect.top + 108,72,26},
            {pControl->winrect.left + 558,pControl->winrect.top + 108,72,26},
            {pControl->winrect.left + 80,pControl->winrect.top + 470,550,28},
            {pControl->winrect.left + 80,pControl->winrect.top + 470,240,28},
            {pControl->winrect.left + 405,pControl->winrect.top + 470,120,28},
            {pControl->winrect.left + 405,pControl->winrect.top + 470,240,32},
            {pControl->winrect.left + 80,pControl->winrect.top + 470,240,28}, 
            {pControl->winrect.left + 0,pControl->winrect.top + 0,720,48},
            {pControl->winrect.left + 0,pControl->winrect.top + 528,720,48}
          
            };
            for(iLoop=0; iLoop < 26; iLoop++)
                memcpy(&(pControl->draw_info[iLoop]), &StandardDrawRect[iLoop], sizeof(RECT));
            break ;                  
                 
          

	case OsdSize480i:
	case OsdSize480p:
	case OsdSize480iCVBS:
	#ifdef SUPPORT_VGA	
	case OsdSizeVga:
	#endif
	default:
            pControl->winrect.top = pControl->parent->winrect.top + 0;
            pControl->winrect.left = pControl->parent->winrect.left + 0;
            pControl->winrect.width = 720;
            pControl->winrect.height = 576;
            pControl->draw_info_num = 26;
            RECT StandardRect[26] = {
            {pControl->winrect.left + 0,pControl->winrect.top + 0,720,480},
            {pControl->winrect.left + 30,pControl->winrect.top + 10,120,78},
            {pControl->winrect.left + 72,pControl->winrect.top + 110,114,98},
            {pControl->winrect.left + 188,pControl->winrect.top + 110,114,98},
            {pControl->winrect.left + 304,pControl->winrect.top + 110,114,98},
            {pControl->winrect.left + 420,pControl->winrect.top + 110,114,98},
            {pControl->winrect.left + 536,pControl->winrect.top + 110,114,98},
            {pControl->winrect.left + 72,pControl->winrect.top + 210,114,98},
            {pControl->winrect.left + 188,pControl->winrect.top + 210,114,98},
            {pControl->winrect.left + 304,pControl->winrect.top + 210,114,98},
            {pControl->winrect.left + 420,pControl->winrect.top + 210,114,98},
            {pControl->winrect.left + 536,pControl->winrect.top + 210,114,98},
            {pControl->winrect.left + 72,pControl->winrect.top + 310,114,98},
            {pControl->winrect.left + 188,pControl->winrect.top + 310,114,98},
            {pControl->winrect.left + 304,pControl->winrect.top + 310,114,98},                              
            {pControl->winrect.left + 420,pControl->winrect.top + 310,114,98},
            {pControl->winrect.left + 536,pControl->winrect.top + 310,114,98},            
            {pControl->winrect.left + 558,pControl->winrect.top + 60,72,26},
            {pControl->winrect.left + 558,pControl->winrect.top + 60,72,26},
            {pControl->winrect.left + 80,pControl->winrect.top + 422,550,28},
            {pControl->winrect.left + 80,pControl->winrect.top + 422,240,26},
            {pControl->winrect.left + 405,pControl->winrect.top + 422,240,32},
            {pControl->winrect.left + 405,pControl->winrect.top + 422,120,28},
            {pControl->winrect.left + 80,pControl->winrect.top + 422,240,26},
            {pControl->winrect.left + 0,pControl->winrect.top + 480,720,48},
            {pControl->winrect.left + 0,pControl->winrect.top + 528,720,48}
            };
            for(iLoop=0; iLoop < 26; iLoop++)
                memcpy(&(pControl->draw_info[iLoop]), &StandardRect[iLoop], sizeof(RECT));
            break ;
    }//end of switch
    TOP=GetFileNamePosition(pControl,CurOsdSize);
    return;
}

HWND *CreateControl15PicBar(HWND *pParent)
{

    HWND *pNewControl = AWCreateWinControl("TControl","15PicBar",(WS_CHILDWINDOW | WS_CHILDWINDOW),
		         0,0,720,576,pParent,0,Win15PicBarMsgProc) ;
    pNewControl->win_id = 2 ;
    pNewControl->draw_info_num = 26;
    pNewControl->draw_info = (PDRAWINFO)AVMem_umalloc(sizeof(DRAWINFO) * pNewControl->draw_info_num) ;
    DRAWINFO DrawDatas[26] = {
        //{0,0,0,0,(INT32U)ICON_PHOTO_BACKGROUND,DT_RLE_BMP_DATA},
        {0,0,0,0,(INT32U)0,DT_RLE_BMP_DATA},
        {0,0,0,0,(INT32U)ICON_PHOTO_TOP,DT_RLE_BMP_DATA},
        {0,0,0,0,(INT32U)ICON_PIC_FOCUS,DT_RLE_BMP_DATA},
        {0,0,0,0,(INT32U)ICON_PIC_LOSE,DT_RLE_BMP_DATA},
        {0,0,0,0,(INT32U)ICON_PIC_LOSE,DT_RLE_BMP_DATA},
        {0,0,0,0,(INT32U)ICON_PIC_LOSE,DT_RLE_BMP_DATA},
        {0,0,0,0,(INT32U)ICON_PIC_LOSE,DT_RLE_BMP_DATA},
        {0,0,0,0,(INT32U)ICON_PIC_LOSE,DT_RLE_BMP_DATA},
        {0,0,0,0,(INT32U)ICON_PIC_LOSE,DT_RLE_BMP_DATA},
        {0,0,0,0,(INT32U)ICON_PIC_LOSE,DT_RLE_BMP_DATA},
        {0,0,0,0,(INT32U)ICON_PIC_LOSE,DT_RLE_BMP_DATA},
        {0,0,0,0,(INT32U)ICON_PIC_LOSE,DT_RLE_BMP_DATA},
        {0,0,0,0,(INT32U)ICON_PIC_LOSE,DT_RLE_BMP_DATA},
        {0,0,0,0,(INT32U)ICON_PIC_LOSE,DT_RLE_BMP_DATA},
        {0,0,0,0,(INT32U)ICON_PIC_LOSE,DT_RLE_BMP_DATA},
        {0,0,0,0,(INT32U)ICON_PIC_LOSE,DT_RLE_BMP_DATA},
        {0,0,0,0,(INT32U)ICON_PIC_LOSE,DT_RLE_BMP_DATA},
        {0,0,0,0,(INT32U)ICON_PAGE_BACKROUNG,DT_RLE_BMP_DATA},
        {0,0,0,0,(INT32U)0,DT_STRING_DATA},
        {0,0,0,0,(INT32U)ICON_PHOTO_INFO_BACKROUNG,DT_RLE_BMP_DATA},
        {0,0,0,0,(INT32U)0,DT_STRING_DATA},
        {0,0,0,0,(INT32U)ICON_TIME_BACGROUND,DT_RLE_BMP_DATA},
        {0,0,0,0,(INT32U)0,DT_STRING_DATA},
        {0,0,0,0,(INT32U)0,DT_VOSD_DATA},
        {0,0,0,0,(INT32U)0,DT_RLE_BMP_DATA},
        {0,0,0,0,(INT32U)0,DT_RLE_BMP_DATA}
        //{0,0,0,0,(INT32U)ICON_TOP_BOTTOM_BACKGROUND1,DT_RLE_BMP_DATA},
       // {0,0,0,0,(INT32U)ICON_TOP_BOTTOM_BACKGROUND2,DT_RLE_BMP_DATA}
        
        };
    memcpy(pNewControl->draw_info, DrawDatas, sizeof(DRAWINFO) * pNewControl->draw_info_num) ;

    return pNewControl;
}

HWND* CreateMenuWin15Pic(void)
{
    HWND *pNewControl ;
    TWINDOWS *pWin;
    HWND *pWin15Pic = CreateControlWin15Pic(NULL);
    SetWin15PicPos(pWin15Pic,CurrentOsdSize);


    pNewControl= CreateControl15PicBar(pWin15Pic);
    Set15PicBarPos(pNewControl,CurrentOsdSize);

    pWin = (TWINDOWS *)pWin15Pic;
    pWin->pFocusControl = AWFindWinCtrlByName("15PicBar");
    return pWin15Pic;
}

void WinResetWin15PicControlsPos(HWND *pControl, INT8U CurOsdSize)
{
    switch(pControl->win_id){
        case 0://Win15Pic
            SetWin15PicPos(pControl,CurOsdSize) ;
            break ;
        case 2://15PicBar
            Set15PicBarPos(pControl,CurOsdSize) ;
            break ;
    }//end of switch
}
void WinResetWin15PicPos(HWND *pControl, INT8U CurOsdSize)
{
    HWND *pChildControl;
    if(pControl == NULL)
        pControl = AWFindWinCtrlByName("Win15Pic");
    if(pControl == NULL) return ;

    WinResetWin15PicControlsPos(pControl, CurOsdSize) ;
    pChildControl = pControl->children ;
    while(pChildControl != NULL){
    	WinResetWin15PicPos(pChildControl, CurOsdSize) ;
    	pChildControl = pChildControl->siblings ;
	}
	return ;
}
int GetFileNamePosition(HWND* pControl,INT8U CurOsdSize)
{
	int top;
	switch(CurOsdSize){  
		case OsdSize576iCVBS:       
		case OsdSize576i:
		case OsdSize576p:
            	top=470;
            	break;
		case OsdSize480iCVBS:
		case OsdSize480i:
		case OsdSize480p:
	#ifdef SUPPORT_VGA	
		case OsdSizeVga:
	#endif
		top=422;
            	break;
		case OsdSize720p:
            	top=645;
            	break;
		default:
            	break;         
            	
            }
          return top;
}

int GetFileNameTop()
{
	return TOP;
}
            	

